Skip to content

Add initial integration for --json=timings behing -Zsection-timings #15780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 12, 2025

Conversation

Kobzol
Copy link
Member

@Kobzol Kobzol commented Jul 28, 2025

What does this PR try to resolve?

This PR adds initial support into Cargo for JSON timing sections, implemented in rustc in rust-lang/rust#142123. This allows Cargo to read frontend/codegen/linking time from rustc, and thus reporting slightly more detailed data in the cargo build --timings output.

The PR modifies Cargo to tell rustc to emit the section messages (--json=...,timings), and it adds the section timings data to the HTML table output and the JSON output. It does not yet integration different sections in the HTML unit chart (I want to do that as a follow-up).

Note that the JSON timings are currently only supported on the nightly compiler (they are not stabilized). The new behavior is thus gated behing an unstable Cargo flag (-Zsection-timings). When the flag is unused, the HTML table should look more or less the same as before, just that the code now supports both options.

How to test and review this PR?

You can run e.g. this to generate the timing report with a nightly compiler:

export RUSTC=`rustup +nightly which rustc`
target/debug/cargo build -Zsection-timings --timings

on some crate, e.g. ripgrep.

Tracking issue: #15817

@rustbot
Copy link
Collaborator

rustbot commented Jul 28, 2025

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-timings Area: timings S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 28, 2025
@rustbot rustbot added the A-console-output Area: Terminal output, colors, progress bar, etc. label Jul 29, 2025
@@ -64,8 +64,9 @@ pub struct Timings<'gctx> {
cpu_usage: Vec<(f64, f64)>,
}

/// Section of compilation.
struct TimingSection {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind moving the rename into the commit that added it so this commit can be focused just on json output?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this marked as resolved? I'm not seeing it resolved as requested nor an explanation for why it shouldn't happen

@Kobzol
Copy link
Member Author

Kobzol commented Jul 30, 2025

Ok, so based on feedback I'm fine with moving this to a fully dynamic approach.

Before I do that though, do you have any suggestions on how to detect whether the timings flag should be passed to Cargo? Is there any precedent for doing something in Cargo only on the nightly channel, or more precisely only with nightly rustc? Or would you prefer that we add an unstable Cargo flag for this?

@epage
Copy link
Contributor

epage commented Aug 5, 2025

Before I do that though, do you have any suggestions on how to detect whether the timings flag should be passed to Cargo? Is there any precedent for doing something in Cargo only on the nightly channel, or more precisely only with nightly rustc? Or would you prefer that we add an unstable Cargo flag for this?

We discussed this in today's cargo team meeting. We should not enable an unstable rustc feature implicitly but require an explicit opt-in.

  • People using nightly for other functionality (e.g. miri or a sanitizer) shouldn't pick up unstable features they aren't using
  • We'd want more than to assume that rustc outputs it in a compatible way / the flag exists and instead have feature detection which is difficult to get right.

@Kobzol
Copy link
Member Author

Kobzol commented Aug 5, 2025

Fair enough, I'll add an explicit feature flag then. It's true that if it was implicit, if the rustc format changes in the future, it could break nightly cargo users of cargo build --timings. That would be solvable if Cargo was a subtree, but with a submodule it would be quite difficult to ensure that both rustc and cargo change at once.

@Kobzol Kobzol changed the title Add initial integration for --json=timings Add initial integration for --json=timings behing -Zsection-timings Aug 8, 2025
@rustbot rustbot added A-documenting-cargo-itself Area: Cargo's documentation A-unstable Area: nightly unstable support labels Aug 8, 2025
@Kobzol
Copy link
Member Author

Kobzol commented Aug 8, 2025

Ok, I rewrote the PR and updated the PR description. It is now gated behind an unstable -Zsection-timings flag, and it renders the sections into the HTML table in a fully dynamic manner.

@Kobzol
Copy link
Member Author

Kobzol commented Aug 12, 2025

Restructured the commits

Copy link
Contributor

@epage epage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@epage epage added this pull request to the merge queue Aug 12, 2025
Merged via the queue into rust-lang:master with commit 1e52a8c Aug 12, 2025
24 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 12, 2025
@Kobzol Kobzol deleted the timings-linker branch August 12, 2025 18:27
bors added a commit to rust-lang/rust that referenced this pull request Aug 16, 2025
Update cargo

23 commits in 840b83a10fb0e039a83f4d70ad032892c287570a..9a0712751ca9444775c7352d3c942a155b656437
2025-07-30 13:59:19 +0000 to 2025-08-15 20:30:47 +0000
- Fixes error while running the cargo clippy --all-targets -- -D warning (rust-lang/cargo#15843)
- Clarify that `cargo doc --no-deps` is cumulative and won’t delete prev (rust-lang/cargo#15800)
- docs: Formatting and cross-linking to build-dir/target-dir docs (rust-lang/cargo#15840)
- Stabilize `build.build-dir` (rust-lang/cargo#15833)
- make resolve features public for cargo-as-a-library (rust-lang/cargo#15835)
- chore(deps): bump slab from 0.4.10 to 0.4.11 (rust-lang/cargo#15832)
- chore: remove x86_64-apple-darwin from CI and tests (rust-lang/cargo#15831)
- chore(deps): update msrv (3 versions) to v1.87 (rust-lang/cargo#15819)
- perf(package): Always reuse the workspace's target-dir (rust-lang/cargo#15783)
- More helpful error for invalid cargo-features = [] (rust-lang/cargo#15781)
- Add initial integration for `--json=timings` behing `-Zsection-timings` (rust-lang/cargo#15780)
- add is_inherited methods to InheritableDependency and InheritableField (rust-lang/cargo#15828)
- chore(deps): update compatible (rust-lang/cargo#15804)
- docs(unstable): Link out to the Plumbing commands effort (rust-lang/cargo#15821)
- chore(deps): update cargo-semver-checks to v0.43.0 (rust-lang/cargo#15825)
- test(build-std): relax the thread name assertion (rust-lang/cargo#15822)
- chore(deps): update msrv (1 version) to v1.89 (rust-lang/cargo#15815)
- Update semver tests for 1.89 (rust-lang/cargo#15816)
- Accessing each build script's `OUT_DIR` and in the correct order (rust-lang/cargo#15776)
- chore: bump to 0.92.0; update changelog (rust-lang/cargo#15807)
- docs: `-Zpackage-workspace` has been stabilized (rust-lang/cargo#15808)
- chore(deps): update rust crate cargo_metadata to 0.21.0 (rust-lang/cargo#15795)
- docs(build-rs): Fix broken intra-doc links (rust-lang/cargo#15810)

r? ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-console-output Area: Terminal output, colors, progress bar, etc. A-documenting-cargo-itself Area: Cargo's documentation A-timings Area: timings A-unstable Area: nightly unstable support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants